<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2016/12/1
 * Time: 13:53
 */
class CtlRegister extends Controller{
    public function regi()
    {
        if ($_SERVER['REQUEST_METHOD'] == 'POST') {
            $data = $this->R("data");
            if (empty($data["user_name"]) || empty($data["mail_address"]) || empty($data["psd"])) {
                $this->out["error_info"] = "注册信息不能为空";
                $this->tpl = "register.tpl";
            }else {
                //添加到数据库
                $mod = new ModRecordLog();
                if ($mod->addUser($data)) {
                    //添加session
                    $info["user_name"] = $data["user_name"];
                    $info["time"] = time();
                    $_SESSION["token"] = serialize($info);
                    header("Location: " . APP_URL); //跳转到首页
                    exit;
                }
                $this->out["error_info"] = "注册失败";
                $this->tpl = "register.tpl";
            }
        } else {
            $this->tpl = "register.tpl";
        }
    }

    public function checkUser(){
        $user_name = $this->R("user_name");
        $mod = new ModRecordLog();
        $msg["ret"] = $mod->checkUser($user_name);
        $msg["msg"] = "success";
        echo json_encode($msg);
        exit;
    }
}